package edu.uwm.capstone.util;

import java.util.Calendar;
import java.util.TimeZone;

public class DateUtil {
	public static final long MILLIS_PER_DAY = 86400000L;

	public static long convertLocalTimestamp(long paramLong) {
		TimeZone localTimeZone = TimeZone.getDefault();
		Calendar localCalendar = Calendar.getInstance(localTimeZone);
		localCalendar.set(1970, 0, 1, 0, 0, 0);
		for (long l = paramLong;; l -= 2147483647L) {
			if (l <= 2147483647L) {
				localCalendar.add(14, (int) l);
				int i = localCalendar.get(14) + 1000 * localCalendar.get(13)
						+ 1000 * (60 * localCalendar.get(12)) + 1000
						* (60 * (60 * localCalendar.get(11)));
				return paramLong
						- localTimeZone.getOffset(localCalendar.get(0),
								localCalendar.get(1), localCalendar.get(2),
								localCalendar.get(5), localCalendar.get(7), i);
			}
			localCalendar.add(14, 2147483647);
		}
	}

	public static final boolean isCalendarValid(Calendar paramCalendar) {
		try {
			paramCalendar.getTimeInMillis();
			return true;
		} catch (IllegalArgumentException localIllegalArgumentException) {
			DebugUtil.debug("DateUtil", "Exception occured in DateUtil.java");
		}
		return false;
	}

	public static final void trimTime(Calendar currentCalendar) {
		currentCalendar.setLenient(false);
		currentCalendar.set(11, 0);
		currentCalendar.set(12, 0);
		currentCalendar.set(13, 0);
		currentCalendar.set(14, 0);
	}
}